package com.cslg.questionnaires.controller;

import com.cslg.questionnaires.entity.Student;
import com.cslg.questionnaires.service.CheckFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.HashMap;

@Controller
public class StudentCheckFormController {
    @Autowired
    private CheckFormService checkFormService;

    @GetMapping("/StudentCheckForm")
    public ModelAndView GetCheckPage(@RequestParam("page") int page, HttpSession session){
        String userType = (String)session.getAttribute("userType");
        Student student = (Student)session.getAttribute("user");
        int studentId = student.getId();
        String username = student.getStu_name();
        String account = student.getStu_id();
        HashMap<String,Object> msg = checkFormService.getAllForm(studentId,userType,page);
        msg.put("userType",userType);
        msg.put("username",username);
        msg.put("account",account);
        return new ModelAndView("CheckForm", msg);
    }

    @GetMapping("/StudentCheckForm/{questionId}")
    public ModelAndView GetCheckPageByQuestionId(@PathVariable int questionId, @RequestParam("page") int page, HttpSession session){
        String userType = (String)session.getAttribute("userType");
        Student student = (Student)session.getAttribute("user");
        int studentId = student.getId();
        String username = student.getStu_name();
        String account = student.getStu_id();
        HashMap<String,Object> msg = checkFormService.getFormByQuestionId(questionId,studentId,userType,page);
        msg.put("userType",userType);
        msg.put("username",username);
        msg.put("account",account);
        return new ModelAndView("CheckForm", msg);
    }
}
